package www.ph.adali.happy.adapter;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

/*
 * 引导页Adapter
 */

public class GuideAdapter extends PagerAdapter {

//    引导页Activity传递过来的全部的滑动页面
    private List<View> mAllViews;

    public GuideAdapter(List<View> views) {
        this.mAllViews = views;
    }

    @Override
    public int getCount() {
        if (mAllViews != null) {
            return mAllViews.size();
        }
        return 0;
    }


    /**
    * 判断instantiateItem所返回的key是否与一个页面视图对应
    */
    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    /**
     * 给定位置的view添加到viewGroup中，创建并显示出来 ——> 返回一个代表新增页面的key(Object)
     */
    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(mAllViews.get(position));
        return mAllViews.get(position);
    }

    /**
     * 移除一个给定position的页面
     */
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(mAllViews.get(position));
    }
}
